#!/bin/bash

CONTAINER_NAME=we-lightning-postgis
CONTAINER_USER=postgres
BACKUP_PATH=maindb.tar
HOST_BACKUP_PATH=./backup/maindb.tar

# 备份数据库
docker exec -t $CONTAINER_NAME pg_dump -h localhost -U $CONTAINER_USER -d maindb -F tar -f $BACKUP_PATH

# 将备份文件从容器复制到容器外部目录
docker cp $CONTAINER_NAME:$BACKUP_PATH $HOST_BACKUP_PATH

# 删除容器内备份文件
docker exec -t $CONTAINER_NAME rm $BACKUP_PATH

ls -l ${HOST_BACKUP_PATH}